<style lang='stylus' scoped>
.header {
  width: 100%;
  height: 420upx;
  // background url('~@/assets/bg_2@2x.png') no-repeat 100%
  background-size: cover;
}

.cutdown-c {
  width: 400upx;
  height: 220upx;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  text-align: center;
}

.inner {
  width: 100%;
  height: 100%;
}

.inner-item {
  width: 100%;
  height: 100%;
  text-align: center;
  font-size: 48upx;
  border-radius: 50%;
}

.ske {
  width: 100%;
  height: 100%;
  border-radius: 50%;
}

.avatar {
  width: 220rpx;
  height: 100%;
  margin-left: 90rpx;
  border-radius: 32rpx;
  overflow: hidden;
}

.nickname {
  color: #999;
}

.charSize {
  text-align: center;
  width: 100%;
}

.charHeight {
  height;
}
</style>
<template>
  <view class="content ft36">
    <view class="header pr charHeight">
      <view class="cutdown-c bgw mgb10">
        <view class="inner pr flex flex-column-center mgb20">
          <view class="inner-item dlc-primary ft48">
            <view class="avatar">
              <open-data type="userAvatarUrl" default-avatar="./../../static/altMyIcon.png"></open-data>
            </view>
            <!-- <image class="avatar" v-if='userInfo' :src="userInfo.avatarUrl" @error="imgReplace"></image>
            <view v-else class="ske dlc-bg"></view> -->
          </view>
        </view>
        <view class="ftwnickname" v-if="userInfo">
          <span>{{userInfo.nickName}}</span>
        </view>
		<view @click="djLogin" class="ftwnickname" v-else>
		  <span>点击登录</span>
		</view>
      </view>
    </view>
    <view class="body">
      <i-panel>
        <i-cell is-link url="/pagesA/info/index">
          <view>
            <i-icon type="mine" size="20" class="mgr10" />我的信息
          </view>
        </i-cell>

        <i-cell is-link url="/pagesA/wallet/index">
          <view>
            <i-icon type="coupons" size="20" class="mgr10" />我的钱包
          </view>
        </i-cell>

        <i-cell is-link url="/pagesA/userCard/index">
          <view>
            <i-icon type="businesscard" size="20" class="mgr10" />我的月卡
          </view>
        </i-cell>

        <i-cell is-link url="/pagesA/order/list">
          <view>
            <i-icon type="activity" size="20" class="mgr10" />充电记录
          </view>
        </i-cell>

        <i-cell is-link url="/pagesA/ICCard/ICCardList">
          <view>
            <i-icon type="collection" size="20" class="mgr10" />IC卡管理
          </view>
        </i-cell>
        <i-cell is-link url="/pagesA/equipment/nearbyEquipment">
          <view>
            <i-icon type="coordinates" size="20" class="mgr10" />附近设备
          </view>
        </i-cell>
        <i-cell icon="mobilephone" is-link :value="phoneNum" @click="callPhone">
          <view>
            <i-icon type="mobilephone_fill" size="20" class="mgr10" />客服电话
          </view>
        </i-cell>

        <!-- <i-cell  is-link  url='/pagesA/order/list' >
        <view><i-icon type="createtask" size="20" class="mgr10"/>&nbsp;&nbsp;关于我们</view>
        </i-cell>-->
      </i-panel>
    </view>
  </view>
</template>

<script>
import store from "@/store";
import { authorization, systemParamPhone, getUserInfo } from "@/api";
export default {
  data() {
    return {
      unReads: 1,
      province: "",
      phoneNum: "",
      userInf: {},
    };
  },

  methods: {
	  // 点击返回登录页
	  djLogin(){
		  uni.redirectTo({
		    url: `/pagesA/auth/index?openId=${1}`,
		  });
	  },
    callPhone() {
      uni.makePhoneCall({
        phoneNumber:this.phoneNum,
      });
    },
    async getUserInfo() {
      try {
        this.userInf = await getUserInfo();
        this.getCustomerServicePhone();
      } catch (err) {}
    },
    // 获取省份，用于获取省份客服电话，若无则显示总客服电话
    async getCustomerServicePhone() {
      try {
        // 调用服务器接口
        const res = await systemParamPhone(6, {
          userType: 2,
          province: this.userInf.data.data.province,
        });
        if (res.data.data == null) {
          this.getGovNum();
        } else {
          this.phoneNum = res.data.data.parameter;
        }
      } catch (e) {
      }
    },
    // 获取客服号码
    async getGovNum() {
      try{
        const { data } = await systemParamPhone(6, {
        userType: 1,
      });
      if (data.code == 1) {
        this.phoneNum = data.data.parameter;
      }
      }catch(e){}
     
    },
  },
  computed: {
    userInfo() {
      return store.state.user.userInfo;
    },
  },
  onLoad() {
    this.getCustomerServicePhone();
  },
  onReady() {
    this.userInf = {};
    this.getUserInfo();
  },
  onShow() {
    store.dispatch("getUserInfo");
  },
};
</script>

